package com.baykalcakici.cafepicker.picker;

import org.joda.time.LocalTime;

import com.google.common.base.Preconditions;

public class CafeListItem {
  public String name;
  public String location;
  public String url;
  public byte servings;

  private static final byte BREAKFAST_MASK = 0x4;
  private static final byte LUNCH_MASK = 0x2;
  private static final byte DINNER_MASK = 0x1;

  public CafeListItem(String[] row) {
    Preconditions.checkNotNull(row);
    name = row[0];
    location = row[2];
    url = row [3];
    servings = Byte.parseByte(row[1]);
  }

  public boolean isServing(final byte mask) {
    return ((servings & mask) != 0);
  }

  public static byte getCafeNameServingMask(final LocalTime localTime) {
    if (localTime.getHourOfDay() < 10) {
      return BREAKFAST_MASK;
    } else if (localTime.getHourOfDay() < 15) {
      return LUNCH_MASK;
    } else {
      return DINNER_MASK;
    }
  }

  public static byte getCafeHistoryServingMask(final LocalTime localTime) {
    if (localTime.getHourOfDay() < 10) {
      return BREAKFAST_MASK;
    } else if (localTime.getHourOfDay() < 15) {
      return LUNCH_MASK;
    } else {
      return DINNER_MASK;
    }
  }
}
